package com.samehope.ar.util;

import com.samehope.ar.vo.TreeDataVO;

import java.util.List;

/**
 * @Description: 树结构帮助类
 * @Author: ZhangLuo
 * @Email: 1946430@qq.com
 */
public class TreeUtils {

    /**
     * 给树结构封装层级值
     * @param treeDataVOS
     */
    public static void setLevel(List<TreeDataVO> treeDataVOS, Integer level) {

        for (int i = 0; i < treeDataVOS.size(); i++) {
            TreeDataVO var = treeDataVOS.get(i);
            var.setLevel(level);
            List<TreeDataVO> children = var.getChildren();
            if (children != null) {
                setLevel(children, level + 1);
            }
        }
    }

    /**
     * 设置唯一索引ID
     * @param treeDataVOS
     */
    public static void setId(List<TreeDataVO> treeDataVOS) {
        for (TreeDataVO treeDataVO : treeDataVOS) {
            treeDataVO.setId("level1_" + treeDataVO.getKey());

            List<TreeDataVO> level2 = treeDataVO.getChildren();
            if (level2 != null) {
                for (TreeDataVO dataVO : level2) {
                    dataVO.setId("level2_" + dataVO.getKey());

                    List<TreeDataVO> level3 = dataVO.getChildren();
                    if (level3 != null) {
                        for (TreeDataVO vo : level3) {
                            vo.setId("level3_" + vo.getKey());
                        }
                    }
                }
            }
        }
    }

}
